package com.dou.you.che.web.controller.api;

import com.dou.you.che.web.comm.http.response.code.RESTApiCode;
import com.dou.you.che.web.comm.http.response.test.TestUserResponse;
import com.dou.you.che.web.controller.base.BaseAct;
import com.dou.you.che.core.entity.sys.SysUser;
import com.dou.you.che.service.sys.SysUserServiceI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 测试Api
 * @Author 黄国刚【1058118328@qq.com】
 */
@RestController
@EnableSwagger2
@RequestMapping(value = "api/test/user")
@Api(value="TestUserAct",description = "Api测试")
public class TestAct extends BaseAct {

    @Autowired
    private SysUserServiceI userService;

    /**
     * 添加用户
     * @param user
     * @return
     */
    @ApiResponses(value = {
            @ApiResponse(code = 400, message = "添加失败"),
            @ApiResponse(code = 200, message = "添加成功")}
    )
    @RequestMapping(value = "add",method = RequestMethod.POST)
    public TestUserResponse addUser(@RequestBody SysUser user){

        return new TestUserResponse(RESTApiCode.SELECT_FAIL_SAVE);
    }

    /**
     * 获取用户信息
     * @param id
     * @return
     */
    @ApiResponses(value = {
            @ApiResponse(code = 400, message = "获取用户个人信息失败"),
            @ApiResponse(code = 200, message = "获取用户个人信息成功")}
    )
    @RequestMapping(value = "get/{id}",method = RequestMethod.GET)
    public TestUserResponse getUser(@PathVariable(value = "id",required = true) final String id){

        return new TestUserResponse(RESTApiCode.SELECT_SUCCESS_SAVE,userService.queryObject(id));
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @ApiResponses(value = {
            @ApiResponse(code = 400, message = "删除失败"),
            @ApiResponse(code = 200, message = "删除成功")}
    )
    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    public TestUserResponse deleteUser(@PathVariable String id){
        return new TestUserResponse(RESTApiCode.SELECT_DELETE_FAIL);
    }

}
